﻿Imports FSUIPC
Module Fuel

#Region "FSUIPC Addresses Screen 2a - Fuel Tip / Aux / Main."
    ' Left Tanks.
    Dim Fuel_Left_Tip_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen2a", &HB8C)
    Dim Fuel_Left_Aux_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen2a", &HB84)
    Dim Fuel_Left_Main_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen2a", &HB7C)

    ' Right Tanks.
    Dim Fuel_Right_Tip_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen2a", &HBA4)
    Dim Fuel_right_Aux_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen2a", &HB9C)
    Dim Fuel_Right_Main_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen2a", &HB94)
#End Region

#Region "FSUIPC Addresses Screen 2b - Fuel Center / Externals."
    ' Center Tanks.
    Dim Fuel_Center1_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen2b", &HB74)
    Dim Fuel_Center2_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen2b", &H1244)
    Dim Fuel_Center3_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen2b", &H124C)

    ' Externals.
    Dim Fuel_Ext1_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen2b", &H1254)
    Dim Fuel_Ext2_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen2b", &H125C)
#End Region

#Region "Screen 2a - Fuel A."
    Public Sub Display_Screen_A()
        Dim img As New System.Drawing.Bitmap(160, 43)
        Dim screen As Drawing.Graphics = Graphics.FromImage(img)
        Try
            FSUIPC.FSUIPCConnection.Process("Screen2a")

            ' Format Percentages.
            Dim Fuel_Left_Tip_Percent_Calc As Double = (Fuel_Left_Tip_Percent.Value * 100 / (128 * 65536))
            Dim Fuel_Left_Aux_Percent_Calc As Double = (Fuel_Left_Aux_Percent.Value * 100 / (128 * 65536))
            Dim Fuel_Left_Main_Percent_Calc As Double = (Fuel_Left_Main_Percent.Value * 100 / (128 * 65536))

            Dim Fuel_Right_Tip_Percent_Calc As Double = (Fuel_Right_Tip_Percent.Value * 100 / (128 * 65536))
            Dim Fuel_Right_Aux_Percent_Calc As Double = (Fuel_right_Aux_Percent.Value * 100 / (128 * 65536))
            Dim Fuel_Right_Main_Percent_Calc As Double = (Fuel_Right_Main_Percent.Value * 100 / (128 * 65536))

            ' Left Side.
            screen.DrawString("Tip:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(8, 2, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(62, 2, 160, 43))

            screen.DrawString("Aux:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(4, 14, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(62, 14, 160, 43))

            screen.DrawString("Main:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(1, 26, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(62, 26, 160, 43))

            ' Right Side.
            screen.DrawString("Tip:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(87, 2, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(142, 2, 160, 43))

            screen.DrawString("Aux:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(83, 14, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(142, 14, 160, 43))

            screen.DrawString("Main:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(80, 26, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(142, 26, 160, 43))

            screen.DrawLine(Pens.White, 0, 0, 159, 0)
            screen.DrawLine(Pens.White, 0, 37, 159, 37)
            screen.DrawLine(Pens.White, 79, 0, 79, 37)
            screen.DrawLine(Pens.White, 0, 0, 0, 37)
            screen.DrawLine(Pens.White, 159, 0, 159, 37)

            ' Display Data.
            ' Left Side.
            screen.DrawString(FormatNumber(Fuel_Left_Tip_Percent_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(30, 2, 160, 43))
            screen.DrawString(FormatNumber(Fuel_Left_Aux_Percent_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(30, 14, 160, 43))
            screen.DrawString(FormatNumber(Fuel_Left_Main_Percent_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(30, 26, 160, 43))

            ' Right Side.
            screen.DrawString(FormatNumber(Fuel_Right_Tip_Percent_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(109, 2, 160, 43))
            screen.DrawString(FormatNumber(Fuel_Right_Aux_Percent_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(109, 14, 160, 43))
            screen.DrawString(FormatNumber(Fuel_Right_Main_Percent_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(109, 26, 160, 43))

        Catch exFSUIPC As FSUIPCException
            MainTimer.Stop()
            CheckTimer.Start()
        Finally
            G15FS9_Main.lcd.DrawLCD(img)
            G15FS9_Main.lcd.UpdateLCD()
        End Try

    End Sub
#End Region

#Region "Screen 3b - Fuel B."
    Public Sub Display_Screen_B()
        Dim img As New System.Drawing.Bitmap(160, 43)
        Dim screen As Drawing.Graphics = Graphics.FromImage(img)
        Try
            FSUIPC.FSUIPCConnection.Process("Screen2b")

            ' Format Percentages.
            Dim Fuel_Center1_Percent_Calc As Double = (Fuel_Center1_Percent.Value * 100 / (128 * 65536))
            Dim Fuel_Center2_Percent_Calc As Double = (Fuel_Center2_Percent.Value * 100 / (128 * 65536))
            Dim Fuel_Center3_Percent_Calc As Double = (Fuel_Center3_Percent.Value * 100 / (128 * 65536))

            Dim Fuel_Ext1_Percent_Calc As Double = (Fuel_Ext1_Percent.Value * 100 / (128 * 65536))
            Dim Fuel_Ext2_Percent_Calc As Double = (Fuel_Ext2_Percent.Value * 100 / (128 * 65536))

            ' Left Side.
            screen.DrawString("Center 1:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(1, 2, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(64, 2, 160, 43))

            screen.DrawString("Center 2:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(1, 14, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(64, 14, 160, 43))

            screen.DrawString("Center 3:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(1, 26, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(64, 26, 160, 43))

            ' Right Side.
            screen.DrawString("Ext 1:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(81, 2, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(144, 2, 160, 43))

            screen.DrawString("Ext 2:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(81, 14, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(144, 14, 160, 43))

            screen.DrawLine(Pens.White, 0, 0, 159, 0)
            screen.DrawLine(Pens.White, 0, 37, 159, 37)
            screen.DrawLine(Pens.White, 79, 0, 79, 37)
            screen.DrawLine(Pens.White, 0, 0, 0, 37)
            screen.DrawLine(Pens.White, 159, 0, 159, 37)

            ' Display Data.
            ' Center Tanks.
            screen.DrawString(FormatNumber(Fuel_Center1_Percent_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(41, 2, 160, 43))
            screen.DrawString(FormatNumber(Fuel_Center2_Percent_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(41, 14, 160, 43))
            screen.DrawString(FormatNumber(Fuel_Center3_Percent_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(41, 26, 160, 43))
            ' External Tanks.
            screen.DrawString(FormatNumber(Fuel_Ext1_Percent_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(110, 2, 160, 43))
            screen.DrawString(FormatNumber(Fuel_Ext2_Percent_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(110, 14, 160, 43))

        Catch exFSUIPC As FSUIPCException
            MainTimer.Stop()
            CheckTimer.Start()
        Finally
            G15FS9_Main.lcd.DrawLCD(img)
            G15FS9_Main.lcd.UpdateLCD()
        End Try
    End Sub
#End Region

End Module
